﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

using Microsoft.Win32;


namespace SQLDeploymentBuilder.UI.Controls.Environments
{
    /// <summary>
    /// Interaction logic for EnvironmentEditor.xaml
    /// </summary>
    public partial class EnvironmentEditor : UserControl
    {
        public EnvironmentEditor()
        {
            Init(null);
        }

        public EnvironmentEditor(string connectionFile)
        {
            Init(connectionFile);
        }

        private void Init(string connectionFile)
        {
            InitializeComponent();
            SQLDeployAnything.Data.Files.Connections ConnectionsFile;
            if (string.IsNullOrEmpty(connectionFile))
            {
                ConnectionsFile = new SQLDeployAnything.Data.Files.Connections();
            }
            else
            {
                ConnectionsFile = SQLDeployAnything.Data.Files.Connections.Open(connectionFile);
            }
            this.DataContext = ConnectionsFile;
        }

        private void Open_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.CheckFileExists = true;
            ofd.Title = "Select Connection File to Open";
            ofd.Filter = "Xml Files|(*.xml)|All Files|(*.*)";
            ofd.Multiselect = false;
            ofd.DefaultExt = ".xml";
            Nullable<bool> ok = ofd.ShowDialog();
            if (ok == true)
            {
                string file = ofd.FileName;
                this.txt_ConnectionFile.Text = file;
            }
        }

        private void AddClick_Click(object sender, RoutedEventArgs e)
        {
            
            // CoolButton Clicked! Let's show our InputBox.
            //InputBox.Visibility = System.Windows.Visibility.Visible;
        }

        

    }
}
